/**************************************************************
 *		Author :		[JoeBullet]							  *
 *		Version:		[1.0]								  *
 *		License:		[GNU General Public License v3.0]     *
 **************************************************************/	
#ifndef _FBCHAT_CFACEBOOKCLIENT_INCLUDED
#define _FBCHAT_CFACEBOOKCLIENT_INCLUDED

#include "gloox-1.0/src/client.h"
#include "gloox-1.0/src/connectionlistener.h"
#include "gloox-1.0/src/loghandler.h"
#include "gloox-1.0/src/messagehandler.h"
#include "gloox-1.0/src/rosterlistener.h"
#include "gloox-1.0/src/rostermanager.h"
#include "gloox-1.0/src/vcardmanager.h"
#include "gloox-1.0/src/vcardhandler.h"
#include "gloox-1.0/src/delayeddelivery.h"
#include "gloox-1.0/src/message.h"
#include "gloox-1.0/src/disco.h"
#include "tchar.hpp"
#include <queue>
#include "CThread.h"
#include "CThreadData.h"
#include "CFunctions.h"
#include <vector>

#pragma comment(lib, "gloox.lib")

using namespace gloox;

#undef SendMessage

// http://www.facebook.com/editaccount.php?settings&alias=1
// Example: joebullet@chat.facebook.com

class CFacebookClient : public gloox::ConnectionListener,
						public gloox::RosterListener,
						public gloox::MessageHandler,
						public gloox::VCardHandler, 
						public CThread
{
	public:
		typedef void
			*PlayerIdentifier;

		CFacebookClient(PlayerIdentifier Player, const tchar::tstring &Username, const tchar::tstring &Password);
		bool SendMessage(gloox::JID Receiver, tchar::tstring sMessage);
		bool IsConnected();
		void Logout(bool Enforce = false);
		void *GetUserData();
		void getVCard(const tchar::tstring &user);
		gloox::Client *GetClient();
		~CFacebookClient();
	protected:
		virtual int	Execute(CThreadData *pData);
		virtual void handleMessage(const gloox::Message &sender, gloox::MessageSession *session = 0);
		virtual void onConnect();
		virtual bool onTLSConnect(const CertInfo &info);
		virtual void onDisconnect(ConnectionError e);
		virtual void handleVCard(const gloox::JID &jid, const gloox::VCard *v);
		virtual void handleVCardResult(gloox::VCardHandler::VCardContext context, const gloox::JID &jid, gloox::StanzaError se = StanzaErrorUndefined);
		virtual void handleItemSubscribed(const gloox::JID &jid);
		virtual void handleItemAdded(const gloox::JID &jid);
		virtual void handleItemUnsubscribed(const gloox::JID &jid);
		virtual void handleItemRemoved(const gloox::JID &jid);
		virtual void handleItemUpdated(const gloox::JID &jid);
		virtual void handleRoster(const gloox::Roster &roster);
		virtual void handleRosterError(const gloox::IQ &iq);
		virtual void handleRosterPresence(const gloox::RosterItem &item, const tchar::tstring &resource, gloox::Presence::PresenceType presence, const tchar::tstring& msg);
		virtual void handleSelfPresence(const gloox::RosterItem &item, const tchar::tstring &resource, Presence::PresenceType presence, const tchar::tstring& msg);
		virtual bool handleSubscriptionRequest(const gloox::JID &jid, const tchar::tstring &msg);
		virtual bool handleUnsubscriptionRequest(const gloox::JID &jid, const tchar::tstring &msg);
		virtual void handleNonrosterPresence(const gloox::Presence &presence);
	private:
		gloox::Client
			*fbClient;
		gloox::JID
			m_Self;
		CThreadData
			*m_MyData;
		gloox::VCardManager 
			*m_vManager;
		gloox::RosterManager
			*m_RosterManager;
		PlayerIdentifier
			m_MyID;
};

#endif
